//
//  MyTabBar.m
//  微博
//
//  Created by zxy on 2018/12/29.
//  Copyright © 2018 zxy. All rights reserved.
//

#import "MyTabBar.h"
@interface MyTabBar()
@property(nonatomic,strong)UIButton *releaseBtn;
@end
@implementation MyTabBar

-(UIButton *)releaseBtn{
    if(!_releaseBtn){
        _releaseBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_releaseBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [_releaseBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateSelected];
        [_releaseBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [_releaseBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateSelected];
        [_releaseBtn addTarget:self action:@selector(releaseBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_releaseBtn];
    }
    return _releaseBtn;
}

-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat width = self.xmg_width / 5;
    CGFloat height = self.xmg_height;
    NSInteger index = 0;
    for (UIView *subView in self.subviews) {
        CGFloat x = index * width;
        if(index == 2){
            x +=width;
        }
        if(subView.class != NSClassFromString(@"UITabBarButton"))continue;
        subView.frame = CGRectMake(x, 0, width, height);
        index++;
    }
    self.releaseBtn.frame = CGRectMake(0, 0, width, height);
    self.releaseBtn.center = CGPointMake(self.xmg_width * 0.5,self.xmg_height * 0.5);
}

#pragma mark -发布按钮
-(void)releaseBtnClick{
    [[NSNotificationCenter defaultCenter] postNotificationName:XMGReleaseButtonClickNoticationName object:nil];
}
@end
